<template>
  <div style="height: 100%">
    <el-card style="margin-bottom: 15px">
    <el-breadcrumb separator="/">
    <el-breadcrumb-item>导航一/</el-breadcrumb-item>
  </el-breadcrumb>
    </el-card>
  <el-card class="box-card">
    <el-table
        :data="homeData"
        border
        style="width: 100%">
      <el-table-column
          prop="date"
          label="日期"
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="姓名"
          width="180">
      </el-table-column>
      <el-table-column
          prop="address"
          label="地址">
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button  type="primary" size="small" @click="handleClick"
          >编辑</el-button
          >
          <el-button  type="danger" size="small" @click="handleDel(scope.row.name)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        style="float: right; margin-top: 10px"
        background
        layout="prev, pager, next"
        :total="homeData.length">
    </el-pagination>
  </el-card>
  </div>
</template>

<script>

import {ElMessage} from "element-plus";
import {mapState} from "vuex";
import store from '@/store/index'

export default {
  name: "HomeContent",
  // 此语法糖不支持this 所以引入store操作数据
  setup(){
    store.dispatch('getHomeData')
  },
  computed:{
    ...mapState(['homeData']),
  },
  methods:{

    handleClick(){
      ElMessage({
        message: '编辑成功',
        type: 'success',
      })
    },
    handleDel(name){
      ElMessage({
        message: `删除${name}成功`,
        type: 'success',
      })
    }
  }
}
</script>

<style scoped>
 .box-card{
   height: 100%;
 }
</style>